<script>
	
	function delMenus(id) {
		layer.confirm('确定要删除所选菜单吗？删除后不可恢复！', function(index){
			$.post('{{ urlfor "WechatController.DelMenu"}}', {id:id}, function(res){
				if(res.code == 1) {
					layer.msg(res.msg)
				} else {
					dialogReback();
				}
				layer.close(index);
			}, 'json');
		});
	}
	function editMenus(id) {
        var title = '添加菜单';
        if (id > 0) {
            title = "编辑菜单"
        }
        var url = '{{ urlfor "WechatController.EditMenu"}}' + '/' + id;
		layer.open({
            type: 2,
            title: title,
            shadeClose: false,
            shade: 0.2,
            maxmin: false,
            shift: 1,
            area: ['710px', '420px'],
            content: url
        });

		return false;
    }
	function addChildMenus(id) {
		var url = '{{ urlfor "WechatController.EditMenu"}}' + '/0?pid=' + id;
		layer.open({
            type: 2,
            title: '添加子菜单',
            shadeClose: false,
            shade: 0.2,
            maxmin: true,
            shift: 1,
            area: ['660px', '380px'],
            content: url
        });

		return false;
	}
	
	function dialogReback() {
		location.reload();	
	}
	
	$('#createMenus').click(function(){
		layer.confirm('确定要生成菜单吗？', function(index){
			$.post('{{ urlfor "WechatController.CreateMenu"}}', function(res){
				if(res.code == 1) {
					layer.msg(res.msg);
				} else {
					layer.msg('菜单生成完成');
				}
				layer.close(index);
			}, 'json');
		});
		return false;
	});
</script>